package com.ruoyi.web.controller.activity;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TTutelageInfo;
import com.ruoyi.system.service.ITTutelageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 晚托信息Controller
 *
 * @author xiyu
 * @date 2024-12-08
 */
@RestController
@RequestMapping("/activity/tutelage")
public class TTutelageInfoController extends BaseController {
    @Autowired
    private ITTutelageInfoService tTutelageInfoService;

    /**
     * 查询晚托信息列表
     */
    @PreAuthorize("@ss.hasPermi('activity:tutelage:list')")
    @GetMapping("/list")
    public TableDataInfo list(TTutelageInfo tTutelageInfo) {
        startPage();
        List<TTutelageInfo> list = tTutelageInfoService.selectTTutelageInfoList(tTutelageInfo);
        return getDataTable(list);
    }

    /**
     * 导出晚托信息列表
     */
    @PreAuthorize("@ss.hasPermi('activity:tutelage:export')")
    @Log(title = "晚托信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTutelageInfo tTutelageInfo) {
        List<TTutelageInfo> list = tTutelageInfoService.selectTTutelageInfoList(tTutelageInfo);
        ExcelUtil<TTutelageInfo> util = new ExcelUtil<TTutelageInfo>(TTutelageInfo.class);
        util.exportExcel(response, list, "晚托信息数据");
    }

    /**
     * 获取晚托信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:tutelage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tTutelageInfoService.selectTTutelageInfoById(id));
    }

    /**
     * 新增晚托信息
     */
    @PreAuthorize("@ss.hasPermi('activity:tutelage:add')")
    @Log(title = "晚托信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTutelageInfo tTutelageInfo) {
        tTutelageInfo.setCreateBy(getUsername());
        return toAjax(tTutelageInfoService.insertTTutelageInfo(tTutelageInfo));
    }

    /**
     * 修改晚托信息
     */
    @PreAuthorize("@ss.hasPermi('activity:tutelage:edit')")
    @Log(title = "晚托信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTutelageInfo tTutelageInfo) {
        tTutelageInfo.setUpdateBy(getUsername());
        return toAjax(tTutelageInfoService.updateTTutelageInfo(tTutelageInfo));
    }

    /**
     * 删除晚托信息
     */
    @PreAuthorize("@ss.hasPermi('activity:tutelage:remove')")
    @Log(title = "晚托信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids, @PathVariable String tutelageStatus) {
        return toAjax(tTutelageInfoService.deleteTTutelageInfoByIds(ids, tutelageStatus));
    }
}
